# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test01
# Description:  例12.6
# Author:       ASUS
# Date:         2019/3/27
#-------------------------------------------------------------------------------

#创建类set的实例时，为set类的构造方法提供一个元组或列表类型的值，字符串可以看成字符的列表
set1 = set(range(10))
print(type(set1))
print(set1)
set2 = set("hello")
print(set2)
set3 = set(["Bill","John","Mike","John"])
print(set3)

a = set((1,2,3))
b = set([3,5,1,7])
#合并集合
print(a.union(b))
print(a | b)
#求交集
print(a.intersection(b))
print(a & b)
#计算a集合和b集合的差，a和b的差值就是在a中删除b中存在的元素
print(a.difference(b))
print(a - b)
#计算a集合和b集合的对称差
print(a.symmetric_difference(b))
print(a ^ b)
print((a - b) | (b - a))

x = a.copy()
#判断集合是否相同
print(x is a)
#向集合添加一个新的元素
x.add(30)
print(x)
print(a)

c = set([2,3])
#判断c集合是否是a集合的子集
print(c.issubset(a))
print(a.issubset(c))
#判断c集合是否为a集合的超集
print(c.issuperset(a))
print(a.issuperset(c))
d = set([1,2,3])
#判断集合是否相等
print(a == d)
#判断1 是否属于集合d
print(1 in d)
print(10 in d)

